<template xmlns="http://www.w3.org/1999/html">
  <sea-search-box url="/sys/log/log4j/list" quick-search>
    <!-- form-header -->
    <template #title>
      <sea-table-title slot="title" title="[slf4j] 系统运行日志"
                       subtitle="当前界面的按钮都可以点击，后台已经禁用了30天内文件的删除功能。"></sea-table-title>
    </template>

    <!-- form-data -->
    <template #default="{list}">
      <el-table :data="list" border>
        <el-table-column label="日志文件">
          <template #default="{row}">
            <a style="width: 100%;display: inline-block" @click="onAction('download', row, undefined)">
              <i class="fa fa-file-archive-o"></i> {{ row }}
            </a>
          </template>
        </el-table-column>

        <el-table-column label="操作栏" class-name="sea-gap-group">
          <template #default="{row}">
            <a class="text-warning" title="删除当前行" @click="remove(row, list)">
              <i class="fa fa-fw fa-trash"></i>删除
            </a>
            <el-divider direction="vertical"></el-divider>
            <a title="下载日志文件" @click="download(row)">
              <i class="fa fa-fw fa-download"></i>下载
            </a>
          </template>
        </el-table-column>
      </el-table>
    </template>
  </sea-search-box>
</template>

<script setup>
import Layers from "@/lang/layers/index";
import application from "@/starter/application-context";

/**
 *
 * 系统访问日志
 */

/**
 * 事件分发
 *
 * @param row   行级数据，可以直接修改
 */
const download = (row) => {
    application.download('/sys/log/log4j/download?filename=' + encodeURI(row));
}

/**
 * 事件分发
 *
 * @param row   行级数据，可以直接修改
 * @param list  表格全量数据
 */
const remove = (row, list) => {
    Layers.delete({
        url: '/sys/log/log4j/info'
        , method: 'DELETE'
        , params: {filename: row}
    }).then((ret) => {
        if (ret.code === 0) {
            Layers.remove(list, row)
            Layers.succeed();
        }
    });
}
</script>
